//
//  ViewController.m
//  ThirdLoginSDKCreater
//
//  Created by wangbc on 16/8/17.
//  Copyright © 2016年 Shanghai Lianyou Network Technology Co., Ltd. All rights reserved.
//

#import "ViewController.h"
#import <ThirdLoginSDK/ThirdLoginSDK.h>
#import <ThirdLoginSDK/ThirdLoginStorage.h>
#import "WBHttpRequest+WeiboUser.h"
#import <objc/message.h>
#import <TencentOpenAPI/TencentOAuth.h>

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *items;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    get_user_info
    NSLog(@"kOPEN_PERMISSION_GET_USER_INFO : %@",kOPEN_PERMISSION_GET_USER_INFO);
    //    get_simple_userinfo
    NSLog(@"kOPEN_PERMISSION_GET_SIMPLE_USER_INFO : %@",kOPEN_PERMISSION_GET_SIMPLE_USER_INFO);
    //    add_share
    NSLog(@"kOPEN_PERMISSION_ADD_SHARE : %@",kOPEN_PERMISSION_ADD_SHARE);
    //
//    NSLog(@"kQQAPICtrlFlagQQShareDataline : %@",);
    //
//    NSLog(@"kOPEN_PERMISSION_GET_INFO : %@",kOPEN_PERMISSION_GET_INFO);
//    //
//    NSLog(@"kOPEN_PERMISSION_GET_OTHER_INFO : %@",kOPEN_PERMISSION_GET_OTHER_INFO);
//    //
//    NSLog(@"kOPEN_PERMISSION_ADD_TOPIC : %@",kOPEN_PERMISSION_ADD_TOPIC);
    
    
    
    
    
    
    self.items = @[
                   @"新浪微博授权",
                   @"新浪微博获取用户信息",
                   @"新浪微博分享-链接",
                   @"微信授权",
                   @"微信获取用户信息",
                   @"微信好友分享-链接",
                   @"微信好友分享-图片",
                   @"微信朋友圈分享-链接",
                   @"微信朋友圈分享-图片",
                   @"QQ授权",
                   @"QQ获取用户信息",
                   @"QQ好友分享-图片",
                   @"QQ好友分享-链接",
                   @"QQ空间分享-图片",
                   @"QQ空间分享-链接",
                   ];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    cell.textLabel.text = self.items[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *key = self.items[indexPath.row];
    if ([key isEqualToString:@"新浪微博授权"]) {
        [ThirdLoginSDK authorize:SSDKPlatformTypeSinaWeibo settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
        return;
    } else if ([key isEqualToString:@"新浪微博获取用户信息"]) {
        [ThirdLoginSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
    } else if ([key isEqualToString:@"新浪微博分享-链接"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"text" image:[UIImage imageNamed:@"1"] url:nil title:@"title" type:SSDKContentTypeWebPage];
        [ThirdLoginSDK share:SSDKShareTypeSinaWeibo parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            NSLog(@"%@",userData);
        }];
    } else if ([key isEqualToString:@"微信授权"]) {
        [ThirdLoginSDK authorize:SSDKPlatformTypeWechat settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
    } else if ([key isEqualToString:@"微信获取用户信息"]) {
        [ThirdLoginSDK getUserInfo:SSDKPlatformTypeWechat onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
    } else if ([key isEqualToString:@"微信好友分享-链接"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
        [shareParams SSDKSetupShareParamsByText:@"text" image:[NSURL URLWithString:@"http://imgsrc.baidu.com/forum/pic/item/8728212e0efc95616963e5fc.jpg"]
                                            url:url title:@"title" type:SSDKContentTypeWebPage];
        [ThirdLoginSDK share:SSDKShareTypeWechatFriend parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
    } else if ([key isEqualToString:@"微信好友分享-图片"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
        [shareParams SSDKSetupShareParamsByText:@"text" image:
                                            [UIImage imageNamed:@"1"]
                                            url:url title:@"title" type:SSDKContentTypeImage];
        [ThirdLoginSDK share:SSDKShareTypeWechatFriend parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
    } else if ([key isEqualToString:@"微信朋友圈分享-链接"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
        [shareParams SSDKSetupShareParamsByText:@"text"
                                          image:[NSURL URLWithString:@"http://q.qlogo.cn/qqapp/100573263/3B836E6A0292C8819B77D652B8C88F3D/100"]
                                            url:url title:@"title" type:SSDKContentTypeWebPage];
        [ThirdLoginSDK share:SSDKShareTypeWechatTimeLine parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
    } else if ([key isEqualToString:@"微信朋友圈分享-图片"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
        [shareParams SSDKSetupShareParamsByText:@"text" image:[UIImage imageNamed:@"1"] url:url title:@"title" type:SSDKContentTypeImage];
        [ThirdLoginSDK share:SSDKShareTypeWechatTimeLine parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
    } else if ([key isEqualToString:@"QQ授权"]) {
        [ThirdLoginSDK authorize:SSDKPlatformTypeQQ settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
    } else if ([key isEqualToString:@"QQ获取用户信息"]) {
        [ThirdLoginSDK getUserInfo:SSDKPlatformTypeQQ onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
            NSLog(@"%@",user);
        }];
    } else if ([key isEqualToString:@"QQ好友分享-图片"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"helllllllllllo" image:[UIImage imageNamed:@"1"] url:nil title:@"ttttttttttt" type:SSDKContentTypeImage];
        [ThirdLoginSDK share:SSDKShareTypeQQFriend parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
    } else if ([key isEqualToString:@"QQ好友分享-链接"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://sports.qq.com/a/20120510/000650.htm"];
        [shareParams SSDKSetupShareParamsByText:@"helllllllllllo" image:
         [NSURL URLWithString:@"http://q.qlogo.cn/qqapp/100573263/3B836E6A0292C8819B77D652B8C88F3D/100"]
                                            url:url title:@"ttttttttttt" type:SSDKContentTypeWebPage];
        [ThirdLoginSDK share:SSDKShareTypeQQFriend parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
        
    } else if ([key isEqualToString:@"QQ空间分享-图片"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"helllllllllllo" image:[UIImage imageNamed:@"1"] url:nil title:@"ttttttttttt" type:SSDKContentTypeImage];
        [ThirdLoginSDK share:SSDKShareTypeQZone parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
        
    } else if ([key isEqualToString:@"QQ空间分享-链接"]) {
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        NSURL *url = [NSURL URLWithString:@"http://sports.qq.com/a/20120510/000650.htm"];
        [shareParams SSDKSetupShareParamsByText:@"helllllllllllo" image:
         [NSURL URLWithString:@"http://q.qlogo.cn/qqapp/100573263/3B836E6A0292C8819B77D652B8C88F3D/100"]
                                            url:url
                                          title:@"ttttttttttt"
                                           type:SSDKContentTypeWebPage];
        [ThirdLoginSDK share:SSDKShareTypeQZone parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, NSError *error) {
            
        }];
        

        
    }
}


@end
